package com.fresh.auth.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fresh.auth.Service.MenuService;
import com.fresh.auth.mapper.MenuMapper;
import com.fresh.entity.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    MenuMapper menuMapper;
    @Override
    public List<Menu> getMenu(Integer userId) {
        ArrayList<Integer> ridList = menuMapper.getRoleId(userId);
        Integer roleId = Collections.min(ridList);
        ArrayList<Integer> midList = menuMapper.getMenuId(roleId);
        List<Menu> menus = new ArrayList<>();
        for (Integer i : midList) {
            Menu menu = menuMapper.selectOne(new QueryWrapper<Menu>().eq("menu_id",i));
            menus.add(menu);
        }
        return menus;
    }
}
